package com.example.store2024.api;

import com.example.store2024.model.Good;
import com.example.store2024.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/v1/goods",produces = "application/json")
public class GoodApi {
    private GoodService goodService;
    @Autowired
    public void setGoodService(GoodService goodService){
        this.goodService = goodService;
    }
    /**
     * 查询商品的微服务
     * @return 响应结果
     * */
    @GetMapping
    public ResponseEntity<Map<String,Object>> findALl(Good search){
        List<Good> goods = this.goodService.findAll(search);

        return ResponseEntity.ok(Map.of("data",goods));
    }
}
